import axios from "axios";
import { ProfessionalCategory, ProfessionalRole } from "../db";

axios.get("https://api.hh.ru/professional_roles").then(async (res) => {
    await ProfessionalRole.truncate({ cascade: true });
    await ProfessionalCategory.truncate({ cascade: true });

    console.log(res.data);
    res.data.categories.map(async (category) => {
        const profCategory = await ProfessionalCategory.create({
            name: category.name,
        });
        ProfessionalRole.bulkCreate([
            ...category.roles.map((role) => {
                return { name: role.name, categoryId: profCategory.id };
            }),
        ]);
    });
    console.log("Completed");
});
